#include "aepulsespectrum.h"
#include "private/aespectrumprivatedefine.h"
#include "common/dataspecificationutils.h"
#include "common/binaryprocesshelper.h"
#include "common/xmldocument.h"
#include "private/spectrumdatafilecommondefine.h"
#include "common/xmlprocesshelper.h"
#include <QDebug>

namespace DataSpecificationGW
{
    class AEPulseSpectrumPrivate
    {
    public:
        AEPulseExtInformationPrivate m_stAEPulseExtInformationPrivate;
        AEPulseDataPrivate m_stAEPulseDataPrivate;
    };

    AEPulseSpectrum::AEPulseSpectrum()
        : Spectrum(),
          m_pAEPulseSpectrumPrivate(new AEPulseSpectrumPrivate)
    {
        setSpectrumTypeCode(SPECTRUM_CODE_AE_PULSE);
    }

    AEPulseSpectrum::~AEPulseSpectrum()
    {
    }

    /************************************************
     * 函数名   : setDataSpecificationVersion
     * 输入参数 :
       const DataSpecificationVersion eDataSpecificationVersion: 数据规范版本号
     * 输出参数 : NULL
     * 返回值   : void
     * 功能     : 设置数据规范版本号
     ************************************************/
    void AEPulseSpectrum::setDataSpecificationVersion(const DataSpecificationVersion eDataSpecificationVersion)
    {
        Spectrum::setDataSpecificationVersion(eDataSpecificationVersion);
        if (V_1_1_0_0 == eDataSpecificationVersion)
        {
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipTriggerThreshold();
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipOpenTime();
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipShutTime();
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipMaxIntervalTime();
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipGain();
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipSyncSource();
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipSyncState();
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipSyncFrequency();
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.skipDischargeSeverity();
        }
    }

    /************************************************
     * 函数名   : spectrumName
     * 输入参数 : NULL
     * 输出参数 : NULL
     * 返回值   : QString
     * 功能     : 图谱名称
     ************************************************/
    QString AEPulseSpectrum::spectrumName() const
    {
        return STR_FILE_NODE_AE_PULSE;
    }

    /************************************************
     * 函数名   : setAEPulseExtInformation
     * 输入参数 :
       const AEPulseExtInformation& stAEPulseExtInformation: AE相位ExtInformation
     * 输出参数 : NULL
     * 返回值   : void
     * 功能     : 设置AE相位ExtInformation
     ************************************************/
    void AEPulseSpectrum::setAEPulseExtInformation(const AEPulseExtInformation& stAEPulseExtInformation)
    {
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAmpUnit = stAEPulseExtInformation.eAmpUnit;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpLowerLimit = stAEPulseExtInformation.fAmpLowerLimit;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpUpperLimit = stAEPulseExtInformation.fAmpUpperLimit;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAESensorType = stAEPulseExtInformation.eAESensorType;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucPulseIntervalTimeUint = stAEPulseExtInformation.ePulseIntervalUnit;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint = stAEPulseExtInformation.iDataPoint;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability.reserve(8);

        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability.clear();
        for (const quint8& ucDischargeTypeProb : stAEPulseExtInformation.aucPDTypeProbability)
        {
            m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability.push_back(ucDischargeTypeProb);
        }

        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fTriggerThreshold = stAEPulseExtInformation.fTriggerThreshold;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sOpenTime = stAEPulseExtInformation.sOpenTime;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sShutTime = stAEPulseExtInformation.sShutTime;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sMaxIntervalTime = stAEPulseExtInformation.sMaxIntervalTime;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sGain = stAEPulseExtInformation.sGain;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncSource = stAEPulseExtInformation.eSyncSource;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncState = stAEPulseExtInformation.ucSyncState;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fSyncFrequency = stAEPulseExtInformation.fSyncFrequency;
        m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucDischargeSeverity = stAEPulseExtInformation.eDischargeSeverity;
    }

    /************************************************
     * 函数名   : setAEPulseData
     * 输入参数 :
       const AEPulseData& stAEPulseData: AE相位Data
     * 输出参数 : NULL
     * 返回值   : void
     * 功能     : 设置AE相位Data
     ************************************************/
    void AEPulseSpectrum::setAEPulseData(const AEPulseData& stAEPulseData)
    {
        m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.qbaAEPulseData = stAEPulseData.qbaAEPulseData;
    }

    /************************************************
     * 函数名   : getAEPulseExtInformation
     * 输入参数 : NULL
     * 输出参数 :
       AEPulseExtInformation& stAEPulseExtInformation: AE相位ExtInformation
     * 返回值   : void
     * 功能     : 获取AE相位ExtInformation
     ************************************************/
    void AEPulseSpectrum::getAEPulseExtInformation(AEPulseExtInformation &stAEPulseExtInformation)
    {
        stAEPulseExtInformation.eAmpUnit = static_cast<AmpUnit>(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAmpUnit);
        stAEPulseExtInformation.fAmpLowerLimit = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpLowerLimit;
        stAEPulseExtInformation.fAmpUpperLimit = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpUpperLimit;
        stAEPulseExtInformation.eAESensorType = static_cast<AESensorType>(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAESensorType);
        stAEPulseExtInformation.ePulseIntervalUnit = static_cast<PulseIntervalUnit>(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucPulseIntervalTimeUint);
        stAEPulseExtInformation.iDataPoint = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint;

        std::copy(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability.begin(), m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability.end(), stAEPulseExtInformation.aucPDTypeProbability);

        stAEPulseExtInformation.fTriggerThreshold = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fTriggerThreshold;
        stAEPulseExtInformation.sOpenTime = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sOpenTime;
        stAEPulseExtInformation.sShutTime = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sShutTime;
        stAEPulseExtInformation.sMaxIntervalTime = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sMaxIntervalTime;
        stAEPulseExtInformation.sGain = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sGain;
        stAEPulseExtInformation.eSyncSource = static_cast<SyncSource>(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncSource);
        stAEPulseExtInformation.ucSyncState = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncState;
        stAEPulseExtInformation.fSyncFrequency = m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fSyncFrequency;
        stAEPulseExtInformation.eDischargeSeverity = static_cast<DischargeSeverity>(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucDischargeSeverity);
    }

    /************************************************
     * 函数名   : setAEPulseData
     * 输入参数 : NULL
     * 输出参数 :
       AEPulseData& stAEPulseData: AE相位Data
     * 返回值   : void
     * 功能     : 获取AE相位Data
     ************************************************/
    void AEPulseSpectrum::getAEPulseData(AEPulseData& stAEPulseData)
    {
        stAEPulseData.qbaAEPulseData = m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.qbaAEPulseData;
    }

    /************************************************
     * 函数名   : saveBinarySpectrumExtInfo
     * 输入参数 :
       QDataStream& out: 输出流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存二进制可扩展信息段
     ************************************************/
    bool AEPulseSpectrum::saveBinarySpectrumExtInfo(QDataStream& out)
    {
        out.device()->seek(SPECTRUM_HEADER_LENGTH);

        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpUnit) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAmpUnit;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpLowerLimit) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpLowerLimit;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpUpperLimit) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpUpperLimit;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAESensorType) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAESensorType;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipPulseIntervalTimeUint) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucPulseIntervalTimeUint;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipDataPoint) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint;

        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipPDTypeProbability)
        {
            for (const quint8& uPDType : m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability)
            {
                out << uPDType;
            }
        }

        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipTriggerThreshold) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fTriggerThreshold;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipOpenTime) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sOpenTime;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipShutTime) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sShutTime;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipMaxIntervalTime) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sMaxIntervalTime;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipGain) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sGain;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncSource) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncSource;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncState) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncState;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncFrequency) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fSyncFrequency;
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipDischargeSeverity) out << m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucDischargeSeverity;

        DataSpecificationUtils::saveBinaryReservedData(SPECTRUM_BASE_LENGTH - out.device()->size(), out);

        return true;
    }

    /************************************************
     * 函数名   : saveXMLSpectrumExtInfo
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
       QDomElement& element: dom元素
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存XML可扩展信息段
     ************************************************/
    bool AEPulseSpectrum::saveXMLSpectrumExtInfo(XMLDocument& xmlDocumentObj, QDomElement& element)
    {
        xmlDocumentObj.beginElement(element);
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_EXTINFORMATION);

        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpUnit) xmlDocumentObj.setValue(TEXT_AMP_UNIT, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAmpUnit));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpLowerLimit) xmlDocumentObj.setValue(TEXT_AMP_MIN, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpLowerLimit, 'f', 1));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpUpperLimit) xmlDocumentObj.setValue(TEXT_AMP_MAX, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpUpperLimit, 'f', 1));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAESensorType) xmlDocumentObj.setValue(TEXT_SENSOR_TYPE, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAESensorType));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipPulseIntervalTimeUint) xmlDocumentObj.setValue(TEXT_PULSE_INTERVAL_UNIT, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucPulseIntervalTimeUint));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipDataPoint) xmlDocumentObj.setValue(TEXT_DATA_POINT, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipPDTypeProbability) xmlDocumentObj.setValue(TEXT_PD_TYPE_PR, DataSpecificationUtils::dischargeTypeProbabilityVector2QString(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipTriggerThreshold) xmlDocumentObj.setValue(TEXT_TRIGGER_THRESHOLD, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fTriggerThreshold, 'f', 1));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipOpenTime) xmlDocumentObj.setValue(TEXT_OPEN_TIME, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sOpenTime));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipShutTime) xmlDocumentObj.setValue(TEXT_SHUT_TIME, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sShutTime));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipMaxIntervalTime) xmlDocumentObj.setValue(TEXT_MAX_TIME_INTERVAL, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sMaxIntervalTime));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipGain) xmlDocumentObj.setValue(TEXT_GAIN, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sGain));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncSource) xmlDocumentObj.setValue(TEXT_SYNC_SOURCE, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncSource));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncState) xmlDocumentObj.setValue(TEXT_SYNC_STATE, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncState));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncFrequency) xmlDocumentObj.setValue(TEXT_SYNC_FREQ, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fSyncFrequency, 'f', 1));
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipDischargeSeverity) xmlDocumentObj.setValue(TEXT_DISCHARGE_SEVERITY, QString::number(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucDischargeSeverity));

        return true;
    }

    /************************************************
     * 函数名   : saveJSONSpectrumExtInfo
     * 输入参数 :
       rapidjson::Document::AllocatorType& alloc:
       rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存JSON可扩展信息段
     ************************************************/
    bool AEPulseSpectrum::saveJSONSpectrumExtInfo(rapidjson::Document::AllocatorType& alloc, rapidjson::Value& jsonValue)
    {
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpUnit) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAmpUnit, TEXT_AMP_UNIT, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpLowerLimit) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpLowerLimit, TEXT_AMP_MIN, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpUpperLimit) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpUpperLimit, TEXT_AMP_MAX, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAESensorType) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAESensorType, TEXT_SENSOR_TYPE, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipPulseIntervalTimeUint) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucPulseIntervalTimeUint, TEXT_PULSE_INTERVAL_UNIT, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipDataPoint) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint, TEXT_DATA_POINT, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipPDTypeProbability) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability, TEXT_PD_TYPE_PR, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipTriggerThreshold) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fTriggerThreshold, TEXT_TRIGGER_THRESHOLD, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipOpenTime) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sOpenTime, TEXT_OPEN_TIME, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipShutTime) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sShutTime, TEXT_SHUT_TIME, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipMaxIntervalTime) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sMaxIntervalTime, TEXT_MAX_TIME_INTERVAL, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipGain) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sGain, TEXT_GAIN, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncSource) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncSource, TEXT_SYNC_SOURCE, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncState) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncState, TEXT_SYNC_STATE, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncFrequency) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fSyncFrequency, TEXT_SYNC_FREQ, alloc, jsonValue);
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipDischargeSeverity) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucDischargeSeverity, TEXT_DISCHARGE_SEVERITY, alloc, jsonValue);

        return true;
    }

    /************************************************
     * 函数名   : saveBinarySpectrumData
     * 输入参数 :
       QDataStream& out: 输出流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存二进制图谱数据段
     ************************************************/
    bool AEPulseSpectrum::saveBinarySpectrumData(QDataStream& out)
    {
        if (m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint <= 0)
        {
            return false;
        }
        out.device()->seek(SPECTRUM_BASE_LENGTH);

        DataSpecificationUtils::saveBinaryPointerData(out, storageDataType(), m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.qbaAEPulseData.data(), 2 * m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint);

        return true;
    }

    /************************************************
     * 函数名   : saveXMLSpectrumData
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
       QDomElement& element: dom元素
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存XML图谱数据段
     ************************************************/
    bool AEPulseSpectrum::saveXMLSpectrumData(XMLDocument& xmlDocumentObj, QDomElement& element)
    {
        xmlDocumentObj.beginElement(element);
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_DATA);

        QString strData = m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.qbaAEPulseData.toBase64();
        xmlDocumentObj.setValue(STR_SPECTRUM_NODE_DATA, strData);

        return true;
    }

    /************************************************
     * 函数名   : saveJSONSpectrumData
     * 输入参数 :
       rapidjson::Document::AllocatorType& alloc:
       rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存JSON图谱数据段
     ************************************************/
    bool AEPulseSpectrum::saveJSONSpectrumData(rapidjson::Document::AllocatorType& alloc, rapidjson::Value& jsonValue)
    {
        if (!m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.bSkipAEPulseSpectrumData) saveJSONField(m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.qbaAEPulseData, STR_SPECTRUM_NODE_DATA, alloc, jsonValue);
        return true;
    }

    /************************************************
     * 函数名   : parseBinarySpectrumExtInfo
     * 输入参数 :
       QDataStream& in: 输入流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析二进制可扩展信息段
     ************************************************/
    bool AEPulseSpectrum::parseBinarySpectrumExtInfo(QDataStream& in)
    {
        if (!in.device()->seek(SPECTRUM_HEADER_LENGTH))
        {
            qDebug() << "AEPulseSpectrum::parseBinarySpectrumExtInfo failed";
            return false;
        }

        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpUnit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAmpUnit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpUnit);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpLowerLimit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpLowerLimit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpLowerLimit);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAmpUpperLimit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpUpperLimit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpUpperLimit);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipAESensorType, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAESensorType, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAESensorType);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipPulseIntervalTimeUint, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucPulseIntervalTimeUint, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasPulseIntervalTimeUint);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipDataPoint, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasDataPoint);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipPDTypeProbability, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability, 8, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasPDTypeProbability);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipTriggerThreshold, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fTriggerThreshold, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasTriggerThreshold);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipOpenTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sOpenTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasOpenTime);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipShutTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sShutTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasShutTime);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipMaxIntervalTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sMaxIntervalTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasMaxIntervalTime);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipGain, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sGain, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasGain);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncSource, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncSource, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncSource);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncState, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncState, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncState);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipSyncFrequency, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fSyncFrequency, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncFrequency);
        parseBinaryField(in, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bSkipDischargeSeverity, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucDischargeSeverity, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasDischargeSeverity);

        return in.status() == QDataStream::Ok;
    }

    /************************************************
     * 函数名   : parseXMLSpectrumExtInfo
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析XML可扩展信息段
     ************************************************/
    bool AEPulseSpectrum::parseXMLSpectrumExtInfo(XMLDocument& xmlDocumentObj)
    {
        xmlDocumentObj.beginElement(spectrumName());
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_EXTINFORMATION);

        parseXMLField(xmlDocumentObj, TEXT_AMP_UNIT, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAmpUnit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpUnit);
        parseXMLField(xmlDocumentObj, TEXT_AMP_MIN, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpLowerLimit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpLowerLimit);
        parseXMLField(xmlDocumentObj, TEXT_AMP_MAX, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpUpperLimit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpUpperLimit);
        parseXMLField(xmlDocumentObj, TEXT_SENSOR_TYPE, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAESensorType, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAESensorType);
        parseXMLField(xmlDocumentObj, TEXT_PULSE_INTERVAL_UNIT, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucPulseIntervalTimeUint, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasPulseIntervalTimeUint);
        parseXMLField(xmlDocumentObj, TEXT_DATA_POINT, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasDataPoint);
        parseXMLField(xmlDocumentObj, TEXT_PD_TYPE_PR, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasPDTypeProbability);
        parseXMLField(xmlDocumentObj, TEXT_TRIGGER_THRESHOLD, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fTriggerThreshold, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasTriggerThreshold);
        parseXMLField(xmlDocumentObj, TEXT_OPEN_TIME, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sOpenTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasOpenTime);
        parseXMLField(xmlDocumentObj, TEXT_SHUT_TIME, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sShutTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasShutTime);
        parseXMLField(xmlDocumentObj, TEXT_MAX_TIME_INTERVAL, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sMaxIntervalTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasMaxIntervalTime);
        parseXMLField(xmlDocumentObj, TEXT_GAIN, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sGain, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasGain);
        parseXMLField(xmlDocumentObj, TEXT_SYNC_SOURCE, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncSource, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncSource);
        parseXMLField(xmlDocumentObj, TEXT_SYNC_STATE, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncState, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncState);
        parseXMLField(xmlDocumentObj, TEXT_SYNC_FREQ, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fSyncFrequency, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncFrequency);
        parseXMLField(xmlDocumentObj, TEXT_DISCHARGE_SEVERITY, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucDischargeSeverity, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasDischargeSeverity);

        xmlDocumentObj.endElement();
        xmlDocumentObj.endElement();

        return true;
    }

    /************************************************
     * 函数名   : parseJSONSpectrumExtInfo
     * 输入参数 :
       const rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析JSON可扩展信息段
     ************************************************/
    bool AEPulseSpectrum::parseJSONSpectrumExtInfo(const rapidjson::Value& jsonValue)
    {
        parseJSONField(jsonValue, TEXT_AMP_UNIT, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAmpUnit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpUnit);
        parseJSONField(jsonValue, TEXT_AMP_MIN, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpLowerLimit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpLowerLimit);
        parseJSONField(jsonValue, TEXT_AMP_MAX, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fAmpUpperLimit, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAmpUpperLimit);
        parseJSONField(jsonValue, TEXT_SENSOR_TYPE, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucAESensorType, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasAESensorType);
        parseJSONField(jsonValue, TEXT_PULSE_INTERVAL_UNIT, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucPulseIntervalTimeUint, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasPulseIntervalTimeUint);
        parseJSONField(jsonValue, TEXT_DATA_POINT, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasDataPoint);
        parseJSONField(jsonValue, TEXT_PD_TYPE_PR, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.vecPDTypeProbability, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasPDTypeProbability);
        parseJSONField(jsonValue, TEXT_TRIGGER_THRESHOLD, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fTriggerThreshold, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasTriggerThreshold);
        parseJSONField(jsonValue, TEXT_OPEN_TIME, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sOpenTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasOpenTime);
        parseJSONField(jsonValue, TEXT_SHUT_TIME, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sShutTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasShutTime);
        parseJSONField(jsonValue, TEXT_MAX_TIME_INTERVAL, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sMaxIntervalTime, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasMaxIntervalTime);
        parseJSONField(jsonValue, TEXT_GAIN, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.sGain, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasGain);
        parseJSONField(jsonValue, TEXT_SYNC_SOURCE, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncSource, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncSource);
        parseJSONField(jsonValue, TEXT_SYNC_STATE, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucSyncState, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncState);
        parseJSONField(jsonValue, TEXT_SYNC_FREQ, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.fSyncFrequency, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasSyncFrequency);
        parseJSONField(jsonValue, TEXT_DISCHARGE_SEVERITY, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.ucDischargeSeverity, m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.bHasDischargeSeverity);

        return true;
    }

    /************************************************
     * 函数名   : parseBinarySpectrumData
     * 输入参数 :
       QDataStream& in: 输入流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析二进制图谱数据段
     ************************************************/
    bool AEPulseSpectrum::parseBinarySpectrumData(QDataStream& in)
    {
        if (!in.device()->seek(SPECTRUM_BASE_LENGTH))
        {
            qDebug() << "AEPulseSpectrum::parseBinarySpectrumData failed";
            return false;
        }

        DataSpecificationUtils::parseBinaryPointerData(in, storageDataType(), m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.qbaAEPulseData, 2 * m_pAEPulseSpectrumPrivate->m_stAEPulseExtInformationPrivate.iDataPoint);

        return in.status() == QDataStream::Ok;
    }

    /************************************************
     * 函数名   : parseXMLSpectrumData
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析XML图谱数据段
     ************************************************/
    bool AEPulseSpectrum::parseXMLSpectrumData(XMLDocument& xmlDocumentObj)
    {
        xmlDocumentObj.beginElement(spectrumName());
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_DATA);

        m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.qbaAEPulseData = QByteArray::fromBase64(xmlDocumentObj.value(STR_SPECTRUM_NODE_DATA).toLatin1());

        xmlDocumentObj.endElement();
        xmlDocumentObj.endElement();

        return true;
    }

    /************************************************
     * 函数名   : parseJSONSpectrumData
     * 输入参数 :
       const rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析JSON图谱数据段
     ************************************************/
    bool AEPulseSpectrum::parseJSONSpectrumData(const rapidjson::Value& jsonValue)
    {
        parseJSONField(jsonValue, STR_SPECTRUM_NODE_DATA, m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.qbaAEPulseData, m_pAEPulseSpectrumPrivate->m_stAEPulseDataPrivate.bHasAEPulseSpectrumData);

        return true;
    }

}
